package com.example.demo.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @Author yfy2001
 * @date 2024/6/7 13:44
 */
@Configuration
public class DataSourceConfig {
    @Primary
    @Bean(name = "mysql1")
    @ConfigurationProperties(prefix = "spring.datasource.mysql1")
    public DataSource datasource1() {
        return DataSourceBuilder.create().build();
    }

    @Primary
    @Bean(name = "mysql2")
    @ConfigurationProperties(prefix = "spring.datasource.mysql2")
    public DataSource datasource2() {
        return DataSourceBuilder.create().build();
    }
}
